// 导入axios实例
import http , {hostUrl}from './request';
const option = {
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
    }
}
export const host = hostUrl
// 轮播图列表
export const bannerList = (data = {}) => {
    return http.get('/api/banner/list', { params: data })
}
// 注册
export const register = (data = {}) => {
    return http.post('/api/user/register', data, option)
}
// 登录
export const login = (data = {}) => {
    return http.post('/api/user/login', data, option)
}
// 是否在线
export const logged = (data = {}) => {
    return http.post('/api/user/logged', data, option)
}
// 设置密码
export const setPwd = (data = {}) => {
    return http.post('/api/user/pwd', data, option)
}
// 设置头像
export const setUserImg = (data = {}) => {
    return http.post('/api/user/img', data, option)
}
// 上传图片
export const uploadImg = (data = {}) => {
    return http.post('/api/photo/upload', data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}
// 获取用户信息
export const userInfo = (data = {}) => {
    return http.post('/api/user/info', data, option)
}
// 编辑资料
export const editInfo = (data = {})=>{
    return http.post('/api/user/edit', data, option)
}

// 歌曲分类列表
export const songCategory = (data = {}) => {
    return http.get('/api/songCategory/list', { params: data })
}
// 专辑列表 
export const albumItems = (data = {}) => {
    return http.get('/api/album/items', { params: data })
}
// 歌曲列表 
export const songItems = (data = {}) => {
    return http.get('/api/song/items', { params: data })
}
// 搜索歌曲 
export const songSearch = (data = {}) => {
    return http.get('/api/song/search', { params: data })
}
// 获取用户歌单 
export const userPlayList = (data = {}) => {
    return http.get('/api/playList/userlist', { params: data })
}
// 创建歌单 
export const playListAdd = (data = {}) => {
    return http.post('/api/playList/add', data, option)
}
// 删除歌单 
export const playListRemove = (data = {}) => {
    return http.post('/api/playList/remove', data, option)
}
// 获取用户歌单
export const playListUser = (data={})=> {
    return http.get('/api/playList/userlist', { params: data })
}
// 编辑歌单
export const playListModify = (data = {}) => {
    return http.post('/api/playList/modify', data, option)
}
// 获取专辑详情
export const albumDetail = (data = {}) => {
    return http.get('/api/album/detail', { params: data })
}

// 获取专辑歌曲
export const albumSong = (data = {}) => {
    return http.get('/api/song/albumSong', { params: data })
}
// 解析歌词
export const parseLyric = (str) => {
    // 定义提取歌词文本的正则表达式
    let regExp = /\[(\d{2}):(\d{2}).(\d{2})\](.{1,})/;
    // console.log(typeof str);// string
    // 判断这个形参是否有值
    if (str == undefined) return false;

    // 定义数组1 根据换行符把字符串转成数组
    let lyricArr1 = str.split('\n');

    // 删除数组中的最后一个元素，用什么方法？
    lyricArr1.pop();

    // 定义数组2 整合歌词的时间和文本信息
    let lyricArr2 = [];
    // 循环数组1
    for (let i = 0; i < lyricArr1.length; i++) {
        if (regExp.test(lyricArr1[i])) {
            // console.log("符合~~")
            // 检查每一行歌词提取的信息
            // console.log(regExp.exec(lyricArr1[i]))
            let res = regExp.exec(lyricArr1[i])
            // 定义对象 记录每一行歌词
            let m = res[1] - 0;//转number类型
            let s = res[2] - 0;
            let ms = res[3] - 0;
            let text = res[4];
            let time = (m * 60) + s + (ms / 1000);
            // console.log({time});
            let obj = {
                text, //文本
                time, // 秒
                id: i
            };
            // 把每一行整合之后的歌词信息存起来
            lyricArr2.push(obj);
        }
    }
    return lyricArr2;
}

// 添加歌单歌曲
export const addPlayListSong = (data = {}) => {
    return http.post('/api/playListSong/add', data, option)
}
// 删除歌单歌曲
export const removePlayListSong = (data = {}) => {
    return http.post('/api/playListSong/remove', data, option)
}
// 获取歌单歌曲
export const allPlayListSong = (data={})=> {
    return http.get('/api/playListSong/all', { params: data })
}

// 获取歌曲分类列表
export const getCategoryList = (data={})=> {
    return http.get('/api/songCategory/list', { params: data })
}
// 获取分类歌曲列表
export const getCategorySongList = (data={})=> {
    return http.get('/api/song/categorySong', { params: data })
}